package com.ttdj.cmel.activity;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.VideoView;

import com.ttdj.cmel.CMELApplication;
import com.ttdj.cmel.R;
import com.umeng.analytics.MobclickAgent;


public class SplashActivity extends AppCompatActivity {

    VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 设置没有标题栏
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);
        initView();
        initData();
    }

    private void initView() {
        videoView = findViewById(R.id.video_view);
    }

    private void initData() {
        videoView.setVideoURI(Uri.parse(("android.resource://" + getPackageName() + "/" + R.raw.cmel_splash)));
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                Log.d("leihuiming", "onCompletion");
                startActivity(new Intent(CMELApplication.getApplication(), HomeActivity.class));
                finish();
            }
        });
        videoView.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        videoView = null;
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}